package com.qf.hw.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.hw.domain.Student;
import com.qf.hw.mapper.StudentMapper;
import com.qf.hw.service.StudentService;
import com.qf.hw.utils.MapperUtils;

import java.util.List;

public class StudentServiceImpl implements StudentService {
    @Override
    public List<Student> findAll() {
        //通过mapper访问数据库，进行学生信息查询
        StudentMapper mapper = MapperUtils.getMapper(StudentMapper.class);
        List<Student> students = mapper.findAll();
        MapperUtils.close();
        return students;
    }

    @Override
    public PageInfo<Student> findPage(int pageNum, int pageSize) {

        PageHelper.startPage(pageNum,pageSize);

        StudentMapper mapper = MapperUtils.getMapper(StudentMapper.class);
        List<Student> students = mapper.findAll();
        MapperUtils.close();

        return new PageInfo<>(students);
    }

    @Override
    public int insert(Student stu) {
        StudentMapper mapper = MapperUtils.getMapper(StudentMapper.class);
        int count = mapper.insert(stu);
        MapperUtils.close();
        return count;
    }
}
